import java.util.Arrays;

/**
 * @author LKQ
 * @date 2022/1/9 14:55
 * @description O(n)
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[]  nums = {1};
        System.out.println(Arrays.toString(solution.searchRange(nums, 1)));
    }

    public int[] searchRange(int[] nums, int target) {
        int n = nums.length;
        int l = 0, r = n - 1;
        while (l <= r) {
            if (target < nums[l] || target > nums[r]) {
                break;
            }
            if (target == nums[l] && target == nums[r]) {
                return new int[] {l, r};
            }
            if (target > nums[l]) {
                l++;
            }
            if (target < nums[r]) {
                r--;
            }
        }
        // 不存在
        return  new int[]{-1, -1};
    }
}
